package o;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.huawei.appgallery.assistantdock.buoydock.bean.GetBuoyFreeformBlackListResp;
import com.huawei.appgallery.assistantdock.buoydock.bean.GetBuoyFreeformBlackListResp$BlackListItem;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.gamebox.plugin.gameservice.bean.GameInfo;
import com.huawei.hms.support.hianalytics.HiAnalyticsConstant;
import com.huawei.secure.android.common.intent.SafeBroadcastReceiver;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import o.beo.f;

public class bil extends fai implements OnClickListener, bij {
    private View ʻ;
    private View ʼ;
    private ImageView ʽ;
    private boolean ˊ = false;
    private bir ˊॱ;
    private d ˋ;
    private bin ˋॱ;
    private boolean ˎ;
    private String ˏ;
    private TextView ˏॱ;
    private ImageView ͺ;
    private Context ॱ;
    private boolean ॱˊ;
    private ArrayList ॱˋ = new ArrayList();
    private RecyclerView ॱˎ;
    private TextView ॱॱ;
    private GameInfo ॱᐝ;
    private ImageView ᐝ;
    private boolean ᐝॱ = false;

    class d extends SafeBroadcastReceiver {
        final /* synthetic */ bil ॱ;

        private d(bil o_bil) {
            this.ॱ = o_bil;
        }

        public void onReceiveMsg(Context context, Intent intent) {
            if ("com.huawei.appmarket.refreshservicewindow".equals(intent.getAction())) {
                this.ॱ.ʼॱ();
            }
        }
    }

    public bil(Context context, String str, boolean z) {
        boolean z2 = false;
        this.ॱ = context;
        this.ॱˊ = z;
        this.ˏ = str;
        if (big.ˏ(z) && HiAnalyticsConstant.BI_KEY_SERVICE.equals(str)) {
            z2 = true;
        }
        this.ˎ = z2;
        fae ˏ = fam.ॱ().ˏ();
        if (ˏ != null) {
            this.ॱᐝ = ˏ.getGameInfo();
        }
    }

    public View ˊ(int i) {
        if (this.ʼ == null) {
            return null;
        }
        return this.ʼ.findViewById(i);
    }

    public View ˏ() {
        if (this.ॱ != null) {
            this.ʼ = LayoutInflater.from(this.ॱ).inflate(beo$j.ॱ, null);
            ॱᐝ();
            ॱ();
            ॱॱ();
            ॱˎ();
            return this.ʼ;
        } else if (!Logger.ˎ()) {
            return null;
        } else {
            Logger.ˏ("AllEnterWindow", "onCreateView, context == null");
            return null;
        }
    }

    private void ॱ() {
        RecyclerView recyclerView = (RecyclerView) this.ʼ.findViewById(beo$e.ʿॱ);
        this.ˊॱ = new bir(this, this.ॱˋ, this.ॱ);
        recyclerView.setLayoutManager(new GridLayoutManager(this.ॱ, 4));
        recyclerView.setAdapter(this.ˊॱ);
        recyclerView.setNestedScrollingEnabled(false);
        new mi(new o.bir.d(this.ˊॱ)).ˏ(recyclerView);
    }

    private void ॱॱ() {
        this.ॱˎ = (RecyclerView) this.ʼ.findViewById(beo$e.ˎ);
        this.ॱˎ.setLayoutManager(new GridLayoutManager(this.ॱ, 4));
        this.ˋॱ = new bin(this);
        this.ॱˎ.setAdapter(this.ˋॱ);
        this.ॱˎ.setNestedScrollingEnabled(false);
    }

    private void ॱᐝ() {
        this.ॱॱ = (TextView) this.ʼ.findViewById(beo$e.ˑॱ);
        this.ʼ.findViewById(beo$e.ʻ).setOnClickListener(this);
        this.ᐝ = (ImageView) this.ʼ.findViewById(beo$e.ॱॱ);
        this.ʻ = this.ʼ.findViewById(beo$e.ʽˊ);
        this.ʻ.setOnClickListener(this);
        this.ʽ = (ImageView) this.ʼ.findViewById(beo$e.ʼᐝ);
        this.ʼ.findViewById(beo$e.ˈॱ).setOnClickListener(this);
        this.ͺ = (ImageView) this.ʼ.findViewById(beo$e.ˋʽ);
        this.ˏॱ = (TextView) this.ʼ.findViewById(beo$e.ˊʼ);
        TextView textView = (TextView) this.ʼ.findViewById(beo$e.י);
        TextView textView2 = (TextView) this.ʼ.findViewById(beo$e.ˏͺ);
        TextView textView3 = (TextView) this.ʼ.findViewById(beo$e.ͺˏ);
        if ("app".equals(this.ˏ)) {
            if (textView != null) {
                textView.setVisibility(8);
            }
            if (textView2 != null) {
                textView2.setText(f.ˏˏ);
            }
            if (textView3 != null) {
                textView3.setText(f.ˎˏ);
            }
        }
    }

    private void ॱˎ() {
        this.ˋ = new d();
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.appmarket.refreshservicewindow");
        ll.ˏ(ContentManager.getInstant().getContext().getApplicationContext()).ˏ(this.ˋ, intentFilter);
    }

    private void ॱˋ() {
        if (HiAnalyticsConstant.BI_KEY_SERVICE.equals(this.ˏ)) {
            this.ॱˋ = bim.ˏ(this.ॱᐝ, this.ॱˊ);
        } else {
            this.ॱˋ = bim.ˊ(this.ॱᐝ, this.ॱˊ);
        }
        this.ˊॱ.ˊ(this.ॱˋ);
        this.ˊॱ.ˊ(this.ˊ);
        this.ˊॱ.ˊ();
        this.ˋॱ.ॱ(this.ˊ);
        ˊˊ();
    }

    private void ʼॱ() {
        ˊˋ();
        ॱˋ();
    }

    private void ʽॱ() {
        if (this.ˋॱ != null) {
            this.ˋॱ.ॱ();
            ˋˋ();
        }
    }

    public void onClick(View view) {
        if (view.getId() == beo$e.ʻ) {
            if (this.ˊ) {
                ˊᐝ();
            } else {
                ॱ(this.ॱ);
            }
        } else if (view.getId() == beo$e.ʽˊ) {
            if (!this.ˊ && this.ˎ) {
                ʾ();
            }
        } else if (view.getId() != beo$e.ˈॱ) {
        } else {
            if (this.ˊ) {
                ˉ();
            } else if (this.ˎ) {
                ʿ();
            } else {
                ʾ();
            }
        }
    }

    private void ʾ() {
        ॱ("EDIT", ˈ());
        ˎ(true);
    }

    private String ˈ() {
        String str = null;
        if ("app".equals(this.ˏ)) {
            str = "ALLAPPS";
        } else if (HiAnalyticsConstant.BI_KEY_SERVICE.equals(this.ˏ)) {
            str = "ALLSERVICE";
        }
        Logger.ˎ("AllEnterWindow", "getFuncUri = " + str);
        return str;
    }

    private void ʿ() {
        fam.ॱ().ॱ(this.ॱ, new bhn(this.ॱ, this.ॱˊ));
    }

    private void ˉ() {
        if (HiAnalyticsConstant.BI_KEY_SERVICE.equals(this.ˏ)) {
            biu.ˋ().ॱ(this.ˊॱ.ʼ());
        } else if ("app".equals(this.ˏ)) {
            biu.ˋ().ˊ(this.ˊॱ.ʼ());
        }
        ˎ(false);
    }

    private void ˊᐝ() {
        ˎ(false);
        ʼॱ();
    }

    private void ˊˋ() {
        if (this.ˊ) {
            this.ˏॱ.setVisibility(0);
            this.ॱॱ.setText(f.ˎ);
            this.ᐝ.setImageResource(beo$d.ʻॱ);
            this.ʻ.setVisibility(8);
            this.ͺ.setImageResource(beo$d.ʼॱ);
            return;
        }
        this.ˏॱ.setVisibility(8);
        if (HiAnalyticsConstant.BI_KEY_SERVICE.equals(this.ˏ)) {
            this.ॱॱ.setText(f.ॱ);
        } else {
            this.ॱॱ.setText(f.ˏ);
        }
        this.ᐝ.setImageResource(beo$d.ʼ);
        if (this.ˎ) {
            this.ʻ.setVisibility(0);
            this.ʽ.setImageResource(beo$d.ˋˊ);
            this.ͺ.setImageResource(beo$d.ॱˎ);
            return;
        }
        this.ʻ.setVisibility(8);
        this.ͺ.setImageResource(beo$d.ˋˊ);
    }

    private void ˎ(boolean z) {
        this.ˊ = z;
        if (this.ˋॱ != null) {
            this.ˋॱ.ॱ(z);
            this.ˋॱ.ˊ();
        }
        if (this.ˊॱ != null) {
            this.ˊॱ.ˊ(z);
            this.ˊॱ.ˊ();
        }
        ˊˋ();
    }

    public void ˊ(Object obj) {
        if (!(this.ॱˋ.size() >= 8 || bim.ॱ(obj) || this.ॱˋ.contains(obj))) {
            ॱ("ADD", obj);
            this.ॱˋ.add(this.ॱˋ.size() + -1 < 0 ? 0 : this.ॱˋ.size() - 1, obj);
            this.ˊॱ.ˊ();
        }
        ʽॱ();
    }

    public void ˏ(Object obj) {
        this.ॱˋ.remove(obj);
        this.ˊॱ.ˊ();
        ॱ("REMOVE", obj);
        ʽॱ();
    }

    private void ˊˊ() {
        new Thread(new Runnable(this) {
            final /* synthetic */ bil ˋ;

            {
                this.ˋ = r1;
            }

            public void run() {
                this.ˋ.ˋॱ.ˊ(this.ˋ.ॱˋ);
                if (HiAnalyticsConstant.BI_KEY_SERVICE.equals(this.ˋ.ˏ)) {
                    this.ˋ.ˋॱ.ॱ(bim.ˋ(this.ˋ.ॱᐝ, this.ˋ.ॱˊ));
                } else {
                    List ˏ = bii.ˏ(this.ˋ.ॱᐝ);
                    this.ˋ.ˋॱ.ॱ(ˏ);
                    this.ˋ.ˏ((ArrayList) ˏ);
                }
                if (this.ˋ.ॱ != null) {
                    new Handler(this.ˋ.ॱ.getMainLooper()).post(new Runnable(this) {
                        final /* synthetic */ AnonymousClass5 ˊ;

                        {
                            this.ˊ = r1;
                        }

                        public void run() {
                            this.ˊ.ˋ.ˋॱ.ॱ();
                            this.ˊ.ˋ.ˋˋ();
                        }
                    });
                } else {
                    Logger.e("AllEnterWindow", "notifyDataSetChanged in main thread fail, context = null");
                }
            }
        }).start();
    }

    private void ˏ(ArrayList<a> arrayList) {
        ArrayList arrayList2 = (ArrayList) arrayList.clone();
        ArrayList ˋॱ = biu.ˋ().ˋॱ();
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            if (ˋॱ.contains(((a) it.next()).ॱ())) {
                it.remove();
            }
        }
        if (!this.ᐝॱ) {
            ˎ(arrayList2);
            this.ᐝॱ = true;
        }
    }

    private void ˎ(final ArrayList<a> arrayList) {
        ArrayList arrayList2 = new ArrayList();
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            arrayList2.add(((a) it.next()).ॱ());
        }
        cfw.ˎ(bfq.ˎ(this.ॱᐝ, arrayList2), new IServerCallBack(this) {
            final /* synthetic */ bil ˋ;

            public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
                if (responseBean == null || responseBean.getResponseCode() != 0 || responseBean.getRtnCode_() != 0) {
                    Logger.e("AllEnterWindow", "request blacklist fail, responseBean.getResponseCode()");
                } else if (responseBean instanceof GetBuoyFreeformBlackListResp) {
                    ArrayList ॱ = ((GetBuoyFreeformBlackListResp) responseBean).ॱ();
                    if (ॱ == null) {
                        Logger.ˋ("AllEnterWindow", "filterAppFromBlackList fail, blackList = null");
                        return;
                    }
                    ArrayList arrayList = new ArrayList();
                    Iterator it = ॱ.iterator();
                    while (it.hasNext()) {
                        GetBuoyFreeformBlackListResp$BlackListItem getBuoyFreeformBlackListResp$BlackListItem = (GetBuoyFreeformBlackListResp$BlackListItem) it.next();
                        if (getBuoyFreeformBlackListResp$BlackListItem.ˋ() == 1) {
                            arrayList.add(getBuoyFreeformBlackListResp$BlackListItem.ˎ());
                        }
                    }
                    Logger.ˎ("AllEnterWindow", "get freeform blacklist form server: " + arrayList);
                    biu.ˋ().ˋ(arrayList);
                    it = arrayList.iterator();
                    while (it.hasNext()) {
                        if (arrayList.contains(((a) it.next()).ॱ())) {
                            it.remove();
                        }
                    }
                }
            }

            public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                if (responseBean != null && responseBean.getResponseCode() == 0 && responseBean.getRtnCode_() == 0) {
                    this.ˋ.ˋॱ.ॱ(arrayList);
                    this.ˋ.ˋॱ.ॱ();
                    this.ˋ.ˋˋ();
                }
            }
        });
    }

    public void D_() {
        super.D_();
        ˋˊ();
    }

    private void ˋˊ() {
        if (this.ˋ != null) {
            ll.ˏ(ContentManager.getInstant().getContext().getApplicationContext()).ˋ(this.ˋ);
        }
    }

    private void ॱ(String str, Object obj) {
        String str2 = "";
        if (obj instanceof String) {
            obj = (String) obj;
        } else if (obj instanceof a) {
            obj = ((a) obj).ˊ();
        } else {
            String str3 = str2;
        }
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        linkedHashMap.put("action", str);
        linkedHashMap.put("service_type", String.valueOf(4));
        linkedHashMap.put("package_name", beq.ˎ());
        linkedHashMap.put("func_uri", obj);
        dgh.ˋ("action_buoy_service_edit", linkedHashMap);
    }

    public void B_() {
        super.B_();
        this.ᐝॱ = false;
        ʼॱ();
    }

    private void ˋˋ() {
        if (this.ʼ != null) {
            View findViewById = this.ʼ.findViewById(beo$e.ᐝ);
            if (findViewById != null) {
                if (this.ˋॱ == null || this.ˋॱ.ᐝ()) {
                    findViewById.setVisibility(8);
                } else {
                    findViewById.setVisibility(0);
                }
            }
            if (this.ॱˎ == null) {
                return;
            }
            if (this.ˋॱ == null || this.ˋॱ.ᐝ()) {
                this.ॱˎ.setVisibility(8);
            } else {
                this.ॱˎ.setVisibility(0);
            }
        }
    }
}
